package com.slt.android.animation;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

/**
 * Created by dp on 2018/4/3.
 */

public class MyAdapter extends BaseAdapter {
    String[] arry;
    Context mContext;
    public MyAdapter (String[] arry , Context mContext){
        this.arry = arry;
        this.mContext = mContext;
    }

    @Override
    public int getCount() {
        return arry.length;
    }

    @Override
    public Object getItem(int position) {
        return arry[position];
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if(convertView == null){
            viewHolder = new ViewHolder();
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_list , null);
            viewHolder.imageView = (ImageView) convertView.findViewById(R.id.iv);
            viewHolder.tvContent = (TextView) convertView.findViewById(R.id.tv);
            convertView.setTag(viewHolder);
        }else {
            viewHolder = (ViewHolder) convertView.getTag();
        }

        viewHolder.tvContent.setText(arry[position]);
        return convertView;
    }

    class ViewHolder {
        ImageView imageView;
        TextView tvContent;
    }
}
